<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <script>
   let arr = [3,1,2,6,8,2,4,9]
  //  let len = arr.length
  //  for (let i = 0; i < len-1; i++) { //比较的轮次
  //   for (let j = 0; j < len-1-i; j++) { // 每轮比较的次数
  //     if(arr[j]>arr[j+1]) {
  //       const tem = arr[j]
  //       arr[j] = arr[j+1]
  //       arr[j+1] = tem
  //     }
  //   }
  //  }
  //  console.log(arr);

  for (let i = 0; i < arr.length-1; i++) {
    for(var j=0;j<arr.length-i-1;j++) {
      if(arr[j]>arr[j+1]) {
        var tem = arr[j]
        arr[j] = arr[j+1]
        arr[j+1] = tem
      }
    }
  }
  console.log(arr);
  console.log(new Set(arr))
  </script>
</body>
</html>